<?php if (!defined('THINK_PATH')) exit();?><!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>用户地图</title>
	<style type="text/css">
		*{
			margin:0px;
			padding:0px;
		}
		#container{
			width: 100%;
			height:750px;
			margin: 0px auto;
			background: #111111;
		}
		#top{
			width:100%;
			height:50px;
			background-color:#06D995;
			color: #fff;
			line-height: 50px;
			font-family: 宋体;
		}
		#main{
			width:100%;
			height: auto;
		}
		#allmap{
			width: 100%;
			height: 600px;
		}
		.foot{
			color: #fff;
		}
	</style>
	<script src="/Storey/Public/js/jquery.min.js"></script>
	<script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=uGu7CKGh7yjjXyxWgqDV6C8booQd01g2"></script>
</head>
<body>
	<div id="container">
		<div id="top">
			<h1>消防监测后台管理系统</h1>
		</div>
		<div id="main">
			<div id="allmap"></div>
		</div>
		<div class="foot">
	        <p align="center">Copyright © 1996 - 2016 w &amp; c. All Rights Reserved.</p>
	        <p align="center">Powered By:lauwen &amp; cc.</p>
	    </div>
	</div>
</body>
<script type="text/javascript">
	// 百度地图API功能
	// 百度地图API功能	
	map = new BMap.Map("allmap");
	var data_info = [];

		$.ajax({
			url: "<?php echo U('Index/getMap');?>",
			type: 'post',
			dataType: 'json',
			success: function(data){
				var da = eval(data);
				// console.log(data);
				$.each(da,function(index, el) {
					// el['buildingNum'];
					data_info[index] = [el.longitude,el.atitude,"所在地址："+el.buildingadd,"<br/>区域编号："+el.regionnum,"<br/>楼宇编号："+el.buildingnum,"<br/>设备数量："+el.deviceCount];
					// console.log(index);
					// console.log(el);
				});
				for(var i=0;i<data_info.length;i++){
					var marker = new BMap.Marker(new BMap.Point(data_info[i][0],data_info[i][1]));  // 创建标注
					var content = data_info[i][2] + data_info[i][3] + data_info[i][4] + data_info[i][5];
					map.addOverlay(marker);               // 将标注添加到地图中
					addClickHandler(content,marker);
				}
				// console.log(data_info);
			}
		})
		
	map.centerAndZoom(new BMap.Point(113.551404,22.368196), 16);
	var opts = {
				width : 300,     // 信息窗口宽度
				height: 150,     // 信息窗口高度
				title : "楼宇设备信息" , // 信息窗口标题
				enableMessage:true//设置允许信息窗发送短息
			   };
	function addClickHandler(content,marker){
		marker.addEventListener("click",function(e){
			openInfo(content,e)}
		);
	}
	function openInfo(content,e){
		var p = e.target;
		var point = new BMap.Point(p.getPosition().lng, p.getPosition().lat);
		var infoWindow = new BMap.InfoWindow(content,opts);  // 创建信息窗口对象 
		map.openInfoWindow(infoWindow,point); //开启信息窗口
	}
</script>
</html>